package com.example.system.controller.question;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.Result;
import com.example.common.core.domain.TableDataInfo;
import com.example.system.domain.question.dto.QuestionAddDTO;
import com.example.system.domain.question.dto.QuestionEditDTO;
import com.example.system.domain.question.dto.QuestionQueryDTO;
import com.example.system.domain.question.vo.QuestionDetailVO;
import com.example.system.domain.question.vo.QuestionVO;
import com.example.system.service.question.IQuestionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/question")
@Tag(name = "题目管理接口")
public class QuestionController extends BaseController {

    @Autowired
    private IQuestionService questionService;

    //获取题目列表
    @GetMapping("/list")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        List<QuestionVO> questionVOList = questionService.list(questionQueryDTO);
        return getTableDataInfo(questionVOList);
    }
    //新增题目
    @PostMapping("/add")
    public Result add(@Validated @RequestBody QuestionAddDTO questionAddDTO) {
        return toResult(questionService.add(questionAddDTO));
    }

    //获取题目详情
    @GetMapping("/detail")
    public Result<QuestionDetailVO> detail(Long questionId) {
            return Result.ok(questionService.detail(questionId));
    }

    //编辑题目
    @PostMapping("/edit")
    public Result<Void> edit(@Validated @RequestBody  QuestionEditDTO questionEditDTO){
        return toResult(questionService.edit(questionEditDTO));
    }

    //删除题目
    @DeleteMapping("/delete")
    public Result<Void> delete(Long questionId){
        return toResult(questionService.delete(questionId));
    }


}
